<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function dec2bin(decNumber){ //传入一个十进制数值
    //    1、定义栈对象
        var stack = new Stack()

    //    2、循环操作
        while (decNumber > 0){
            //将余数存入栈中
            stack.push(decNumber % 2)
            //获取整除后的结果作为下一次的除数
            decNumber = Math.floor(decNumber / 2) //Math.floor():返回数字的下舍整数
        }

    //    3。丛栈中取出0和1
        var binaryString = ''
        while(!stack.isEmpty()){ //栈不为空
            binaryString += stack.pop()
        }
        return binaryString
    }
</script>
</body>
</html>